using UnityEngine;
using System.Collections;

[RequireComponent(typeof(SphereCollider))]
[AddComponentMenu("Third Person Props/Pickup")]

public class Pickup : MonoBehaviour
{
	//Check the conversion to C# of these
	public enum PickupType{ Health = 0, FuelCell = 1}
	public PickupType pickupType = PickupType.FuelCell;
	
	public int amount = 1;
	public AudioClip sound;
	public float SoundVolume = 2.0f;
	
	private bool used = false;
	private DroppableMover mover;
	
	void Start()
	{
		mover = GetComponent<DroppableMover>();
	}

	bool ApplyPickup(ThirdPersonStatus playerStatus)
	{
		//Switch statement enables additional Pickup types
		switch (pickupType)
		{
			case PickupType.Health:
				playerStatus.AddHealth(amount);
				break;
			case PickupType.FuelCell:
				playerStatus.FoundItem(amount);
				break;
		}
		
		return true;
	}
	
	void OnTriggerEnter(Collider col)
	{
		if(mover && mover.enabled)
		{
			return;
		}
		
		ThirdPersonStatus playerStatus = (ThirdPersonStatus)col.GetComponent(typeof(ThirdPersonStatus));
		
		//Ensure player collision/double pickups
		if(!ApplyPickup(playerStatus))
		{
			return;
		}
		
		used = true;
		
		//Play Sound
		if(sound)
		{
			AudioSource.PlayClipAtPoint(sound, transform.position, SoundVolume);
		}
		else
		{
			Destroy(gameObject);
		}
	}
	
	void Reset()
	{
		if(collider == null)
		{
			gameObject.AddComponent(typeof(BoxCollider));
		}
		collider.isTrigger = true;
	}
	
}